/* eslint-disable indent */
'use strict'

const Controller = require('egg').Controller
const dayjs = require('dayjs')


/**
 * @controller Desktopcfg 桌面配置模块
 */

class DesktopcfgController extends Controller {

    /**
   * @summary 分页查询桌面配置列表
   * @description 分页查询桌面配置列表
   * @router post /v1/desktopcfg/list
   * @request body DesktopcfgList 分页参数
   * @response 0 DesktopcfgInfo
   */
    async list() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgList, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }

        const data = await service.desktopcfg.getDesktopcfgList(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 新建桌面配置
       * @description 只有登录后才有权限
       * @router post /v1/desktopcfg/create
       * @request body DesktopcfgCreate 新增配置参数
       * @response 0 DesktopcfgInfo
       */
    async create() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgCreate, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.desktopcfg.createDesktopcfg(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 编辑桌面配置
       * @description 只有登录后才有权限
       * @router post /v1/desktopcfg/edit
       * @request body DesktopcfgEdit 参数
       * @response 0 DesktopcfgInfo
       */
    async edit() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgEdit, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.desktopcfg.editDesktopcfg(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 删除桌面配置
       * @description 只有登录后才有权限
       * @router post /v1/desktopcfg/delete
       * @request body DesktopcfgDelete 参数
       * @response 0 DesktopcfgInfo
       */
    async delete() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgDelete, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.desktopcfg.deleteDesktopcfg(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
       * @summary 应用门店桌面配置
       * @description 只有登录后才有权限
       * @router post /v1/desktopcfg/apply
       * @request body DesktopcfgSet 应用参数
       * @response 0 DesktopcfgInfo
       */
    async apply() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgSet, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.desktopcfg.applyDesktopcfg(params)
        if (data) {
            helper.success(data)
        }
    }

    /**
     * @Deprecated
       * @summary 获取当前门店使用配置
       * @description 无需登录
       * @router post /v1/desktopcfg/current
       * @request body DesktopcfgGet 查询参数
       * @response 0 DesktopcfgInfo
       */
    async current() {
        const { service, helper, request, validate, rule } = this.ctx
        const params = request.body

        // 参数校验
        const passed = await validate.call(this, rule.DesktopcfgGet, request.body)
        if (!passed) {
            helper.error(null, '参数错误')
            return
        }
        const data = await service.desktopcfg.getCurrentDesktopcfg(params)
        if (data) {
            helper.success(data)
        }
    }
}


module.exports = DesktopcfgController
